class Solution {
public:
    bool checkPartitioning(string s) {
        int n = s.size();
        vector<vector<bool>> dp(n, vector<bool>(n));
        for (int j = 0;j < n;j++)
        {
            for (int i = j;i >= 0;i--)
            {
                if (i == j) dp[i][j] = true;
                else if (i + 1 == j)
                {
                    if (s[i] == s[j]) dp[i][j] = true;
                }
                else {
                    if (s[i] == s[j]) dp[i][j] = dp[i + 1][j - 1];
                }
            }
        }
        for (int j = 1;j <= n - 2;j++)
        {
            for (int i = j;i >= 1;i--)
            {
                if (dp[i][j])
                {
                    if (dp[0][i - 1] && dp[j + 1][n - 1]) return true;
                }

            }
        }
        return false;
    }
};